package org.esgl3d.primitives;

import java.util.logging.Logger;

import org.esgl3d.Mesh;
import org.esgl3d.Mesh.Format;
import org.esgl3d.rendering.LegacyGLWrapper;
import org.esgl3d.rendering.Renderer;
import org.esgl3d.rendering.VertexContainer;
import org.esgl3d.rendering.VertexFormat;
import org.esgl3d.rendering.VertexContainer.PrimitiveType;

public class Pyramid {
	private static final Logger logger = Logger.getLogger(Pyramid.class.getName());
	
	VertexContainer container = null;
	
	private Pyramid(Renderer r) {
		container = r.createVertexContainer(VertexFormat.F_4Color_3Position, 12);
		LegacyGLWrapper gl = container.getLegacyGLInterface();
		
		gl.glBegin();
		
		gl.glColor4f(1,1.0f,0.0f,0.0f);						// Red
        gl.glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Of Triangle (Front)
        gl.glColor4f(1,0.0f,1.0f,0.0f);						// Green
        gl.glVertex3f(-1.0f,-1.0f, 1.0f);					// Left Of Triangle (Front)
        gl.glColor4f(1,0.0f,0.0f,1.0f);						// Blue
        gl.glVertex3f( 1.0f,-1.0f, 1.0f);					// Right Of Triangle (Front)
        gl.glColor4f(1,1.0f,0.0f,0.0f);						// Red
        gl.glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Of Triangle (Right)
        gl.glColor4f(1,0.0f,0.0f,1.0f);						// Blue
        gl.glVertex3f( 1.0f,-1.0f, 1.0f);					// Left Of Triangle (Right)
        gl.glColor4f(1,0.0f,1.0f,0.0f);						// Green
        gl.glVertex3f( 1.0f,-1.0f, -1.0f);					// Right Of Triangle (Right)
        gl.glColor4f(1,1.0f,0.0f,0.0f);						// Red
        gl.glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Of Triangle (Back)
        gl.glColor4f(1,0.0f,1.0f,0.0f);						// Green
        gl.glVertex3f( 1.0f,-1.0f, -1.0f);					// Left Of Triangle (Back)
        gl.glColor4f(1,0.0f,0.0f,1.0f);						// Blue
        gl.glVertex3f(-1.0f,-1.0f, -1.0f);					// Right Of Triangle (Back)
        gl.glColor4f(1,1.0f,0.0f,0.0f);						// Red
        gl.glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Of Triangle (Left)
        gl.glColor4f(1,0.0f,0.0f,1.0f);						// Blue
        gl.glVertex3f(-1.0f,-1.0f,-1.0f);					// Left Of Triangle (Left)
        gl.glColor4f(1,0.0f,1.0f,0.0f);						// Green
        gl.glVertex3f(-1.0f,-1.0f, 1.0f);					// Right Of Triangle (Left)
        container.synchronize();
	}
	
	public Mesh getMesh() {
		Mesh m = new Mesh();
		m.setVertices(container, Format.Triangle);
		return m;
	}
	
	public static Pyramid createColoredPyramid(Renderer r) {
		return new Pyramid(r);
	}
}
